package com.zmn.oms.admin.controller.work.modify;

import com.zmn.oms.admin.controller.work.WorkBaseController;
import com.zmn.oms.common.dto.ResultDTO;
import com.zmn.oms.model.dto.order.zmn.FactoryUpdateOrderDTO;
import com.zmn.oms.model.dto.order.zmn.ZsNormalUpdateOrderDTO;
import com.zmn.oms.zmn.business.interfaces.order.OrderVerifyBService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

/**
 * @ClassName WorkVerifyController
 * @description: 工单校验
 * @author: wangyanci
 * @create: 2021-07-27 18:57
 * @Version 1.0
 **/
@Slf4j
@Controller
@RequestMapping("/work/modify/verify")
public class WorkVerifyController extends WorkBaseController {

    @Autowired
    private OrderVerifyBService verifyOrderBService;

    /**
     * 普通单修改
     */
    @PostMapping(value = "normal/update")
    @ResponseBody
    public ResultDTO saveUpdate(@RequestBody @Valid ZsNormalUpdateOrderDTO zsNormalUpdateOrderDTO) {
        // 子公司角色修改订单不触发分单撤回、派单撤回
        boolean branchCompany = super.isBranchCompany();
        zsNormalUpdateOrderDTO.setVerifyDistributeBack(!branchCompany);
        zsNormalUpdateOrderDTO.setVerifyAssignBack(!branchCompany);
        return verifyOrderBService.verifyNormalUpdateOrder(zsNormalUpdateOrderDTO);
    }

    /**
     * 厂商单修改
     */
    @PostMapping(value = "factory/update")
    @ResponseBody
    public ResultDTO saveFactoryUpdate(@RequestBody @Valid FactoryUpdateOrderDTO factoryUpdateOrderDTO) {
        // 子公司角色修改订单不触发分单撤回、派单撤回
        boolean branchCompany = super.isBranchCompany();
        factoryUpdateOrderDTO.setVerifyDistributeBack(!branchCompany);
        factoryUpdateOrderDTO.setVerifyAssignBack(!branchCompany);
        return verifyOrderBService.verifyFactoryUpdateOrder(factoryUpdateOrderDTO);
    }

    /**
     * 校验返修是否过保
     */
    @RequestMapping(value = "/rework")
    @ResponseBody
    public ResultDTO verifyRework(Long orderId) {
        return verifyOrderBService.verifyRework(orderId);
    }
}